<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
	</head>

	<body>
		<script src="../script/app.js" type="text/javascript" charset="utf-8"></script>
		<script src="../script/db.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			apiready = function() {
				var func = function(db) {
					var fs = api.require("fs");
					var fd=null;
					fs.open({
					    path: 'widget://res/question.sql',
					    flags: 'read_write'
					},function(ret,err){
					    if (ret.status) {
//					        api.alert({msg:'open操做成功'});
					        fd = ret.fd;
					        fs.read({
							    fd:fd,
							    offset:0,
							    length:0
							},function(ret,err){
							    if (ret.status) {
							    		showWaiting("请勿退出!");
//							        api.alert({msg:ret.status});
									var sqlArray = ret.data.split("\n");
									var slength = sqlArray.length;
									for (var i = 0; i <slength; i++) {
										var sql = sqlArray[i];
										db.executeSql({
											name: 'data',
											sql: sql
										}, function(ret, err) {
											if (ret.status) {
												api.toast({
													msg: "数据更新成功!"
												});
												hideWaiting();
											} else {
												api.toast({
													msg: err.msg
												});
											}
										});
									}
									
									
							    }else{
							        api.alert({msg:err.msg});
							    }
							});
					    }else{
					        api.alert({msg:err.msg});
					    }
					});
//					var sql = 'SELECT COUNT(*) as total FROM question';
//					db.selectSql({
//						name: 'data',
//						sql: sql
//					}, function(ret, err) {
//						if (ret.status) {} else {
//							api.toast({
//								msg: err.msg
//							});
//						}
//					});
				}
				APP.openDb(func);
			}
		</script>
	</body>

</html>